package com.nwpu.am.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.nwpu.am.pojo.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDate;

/**
 * UserLoginVO
 *
 * @author Roy
 * @version 1.0
 * {@code @date} 2024/6/3
 */

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("用户登录返回数据")
public class UserLoginVO implements Serializable {
    private Long userId;
    private String username;
    private String phoneNum;
    private String email;
    @ApiModelProperty("性别（0：男 1：女 2：未知）")
    private Short sex;
    private String address;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    @ApiModelProperty("格式：yyyy-MM-dd")
    private LocalDate birthday;
    @ApiModelProperty("角色（1：管理员 0：修理人员）")
    private Short role;
    private String token;

    /**
     * 根据User内字段和token创建UserLoginVo
     *
     * @param user
     * @param token
     * @return
     */
    public static UserLoginVO userCopy(User user, String token) {
        return UserLoginVO.builder()
                .userId(user.getUserId())
                .username(user.getUsername())
                .phoneNum(user.getPhoneNum())
                .email(user.getEmail())
                .sex(user.getSex())
                .address(user.getAddress())
                .birthday(user.getBirthday())
                .role(user.getRole())
                .token(token)
                .build();
    }
}
